package com.cw.jeeyt.service.converter.api;

import java.util.ArrayList;
import java.util.List;

import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.cw.jeeyt.common.enums.EnumObjType;
import com.cw.jeeyt.service.bo.api.ApiFacadeObjBo;
import com.cw.jeeyt.dao.model.api.ApiFacadeObjDo;
import com.cw.lang.common.utils.CollectionUtil;
import com.cw.lang.common.utils.StringUtil;

/**
 * 接口方法参数对象转换类
 *
 * @author chenw
 * @date 2019-03-10 13:05:36
 */
public class ApiFacadeObjConverter {

    /**
     * do转bo
     *
     * @param model
     * @return
     */
    public static ApiFacadeObjBo do2Bo(ApiFacadeObjDo model) {
        if (model == null) {
            return null;
        }
        String objTypeCn = StringUtil.isNotBlank(model.getObjType()) ? EnumObjType.find(model.getObjType())
            .getDescription() : "";
        ApiFacadeObjBo bo = new ApiFacadeObjBo();
        bo.setId(model.getId());
        bo.setObjCode(model.getObjCode());
        bo.setObjName(model.getObjName());
        bo.setObjComment(model.getObjComment());
        bo.setObjPackage(model.getObjPackage());
        bo.setObjType(model.getObjType());
        bo.setObjTypeCn(objTypeCn);
        bo.setIsPublicObj(model.getIsPublicObj());
        bo.setCreateBy(model.getCreateBy());
        bo.setCreateDate(model.getCreateDate());
        bo.setUpdateBy(model.getUpdateBy());
        bo.setUpdateDate(model.getUpdateDate());
        return bo;
    }

    /**
     * bo转do
     *
     * @param bo
     * @return
     */
    public static ApiFacadeObjDo bo2Do(ApiFacadeObjBo bo) {
        if (bo == null) {
            return null;
        }
        ApiFacadeObjDo model = new ApiFacadeObjDo();
        model.setId(bo.getId());
        model.setObjCode(bo.getObjCode());
        model.setObjName(bo.getObjName());
        model.setObjComment(bo.getObjComment());
        model.setObjPackage(bo.getObjPackage());
        model.setObjType(bo.getObjType());
        model.setIsPublicObj(bo.getIsPublicObj());
        model.setCreateBy(bo.getCreateBy());
        model.setCreateDate(bo.getCreateDate());
        model.setUpdateBy(bo.getUpdateBy());
        model.setUpdateDate(bo.getUpdateDate());
        return model;
    }

    /**
     * doList转boList
     *
     * @param doList
     * @return
     */
    public static List<ApiFacadeObjBo> doList2BoList(List<ApiFacadeObjDo> doList) {
        if (CollectionUtil.isEmpty(doList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(doList.iterator(), ApiFacadeObjConverter::do2Bo));
    }

    /**
     * boList转doList
     *
     * @param boList
     * @return
     */
    public static List<ApiFacadeObjDo> boList2DoList(List<ApiFacadeObjBo> boList) {
        if (CollectionUtil.isEmpty(boList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(boList.iterator(), ApiFacadeObjConverter::bo2Do));
    }
}
